package com.hgb.mall.portal.controller;

import com.hgb.mall.common.api.CommonResult;
import com.hgb.mall.mbg.entity.SmsSearchHistory;
import com.hgb.mall.portal.services.SearchHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: guibo
 * @Description:
 * @Date: Created in 16:56 2021/5/21
 * @Modified By:
 */
@Controller
@Api(tags = "搜索历史管理")
@RequestMapping("/history")
public class SmsHistoryController {
    @Autowired
    SearchHistoryService searchHistoryService;
    @ApiOperation("保存")
    @RequestMapping(value = "/saveSearchHistory", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<Integer> saveSearchHistory(@RequestParam String keyword) {
        return CommonResult.success(searchHistoryService.saveSearchHistory(keyword));
    }

    @ApiOperation("清空")
    @RequestMapping(value = "/deleteAll", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<Integer> deleteAll() {
        return CommonResult.success(searchHistoryService.deleteAll());
    }

    @ApiOperation("列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<SmsSearchHistory>> list() {
        return CommonResult.success(searchHistoryService.list());
    }
}
